package com.example.stock.business.monitor;

import com.example.stock.business.monitor.logic.*;
import com.example.stock.excel.Monitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MonitorFactory implements Trigger {

    @Autowired
    MonthDecreaseCountMonitor monthDecreaseCountMonitor;

    @Autowired
    WeekCloseIncreaseMonitor weekCloseIncreaseMonitor;

    @Autowired
    WeekCloseDecreaseMonitor weekCloseDecreaseMonitor;

    @Autowired
    DayClose15DDownMonitor dayClose15DDownMonitor;

    @Autowired
    PBIncreaseMonitor pbIncreaseMonitor;

    @Autowired
    PBDecreaseMonitor pbDecreaseMonitor;

    @Autowired
    WeekPctMonitor weekPctMonitor;

    @Autowired
    WeekCloseMonitor weekCloseMonitor;

    @Autowired
    MonthLpMonitor monthLpMonitor;


    // 监控中
    private final static int STATE_ON = 1;

    private final static String WEEK_PCT = "周涨跌";

    private final static String WEEK_CLOSE = "周价格";

    private final static String DAY_CLOSE = "日价格";

    public final static String MONTH_DECREASE_COUNT = "连续下跌";

    public final static String WEEK_PRICE_INCREASE = "价格突破";

    public final static String WEEK_PRICE_DECREASE = "价格跌破";

    public final static String PB_INCREASE = "PB突破";

    public final static String PB_DECREASE = "PB跌破";

    public final static String PRICE_MONITOR = "价格监控";

    public final static String MONTH_LP = "分位点";

    @Override
    public boolean trigger(Monitor monitor) {
        if (monitor.getState() != STATE_ON){
            return false;
        }

        return switch (monitor.getType()) {
            case MONTH_DECREASE_COUNT -> monthDecreaseCountMonitor.trigger(monitor);
            case WEEK_PRICE_INCREASE -> weekCloseIncreaseMonitor.trigger(monitor);
            case WEEK_PRICE_DECREASE -> weekCloseDecreaseMonitor.trigger(monitor);
            case DAY_CLOSE -> dayClose15DDownMonitor.trigger(monitor);
            case PB_INCREASE -> pbIncreaseMonitor.trigger(monitor);
            case PB_DECREASE -> pbDecreaseMonitor.trigger(monitor);
            case WEEK_PCT -> weekPctMonitor.trigger(monitor);
            case WEEK_CLOSE -> weekCloseMonitor.trigger(monitor);
            case MONTH_LP -> monthLpMonitor.trigger(monitor);
            default -> false;
        };
    }
}